package com.winit.common.runner;

import com.winit.common.util.Constants;
import com.winit.common.util.ShellRunUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * Created by wangjian on 17/8/18.
 */
@Component
//@Order(value = 1)
public class StartUpRunner implements CommandLineRunner {

    private Logger log = LoggerFactory.getLogger(StartUpRunner.class);

    @Override
    public void run(String... args) throws Exception {
        log.info("===== 初始化开始!!! =====");
        runShell();
        log.info("===== 初始化结束!!! =====");
    }

    private void runShell() {
        StringBuffer filePath = new StringBuffer();
        filePath.append(Constants.SHELL_PATH).append("shell/init.sh");

        String[] param = ShellRunUtil.getShellParam("bash", filePath.toString(), Constants.ROOT_PATH, Constants.DIR_NAME);

        ShellRunUtil.runShell(param);
    }
}
